package com.binance.notification.verifier;

import org.springframework.stereotype.Component;

import com.binance.master.utils.StringUtils;
import com.binance.master.validator.internal.constraintvalidators.iv.IVerifier;
import com.binance.notification.api.push.PushCommand;

@Component
public class PushCommandVerifier implements IVerifier<PushCommand> {

    @Override
    public boolean valid(PushCommand cmd, ValidResult result) {
        if (cmd.getUsers().size() > 0 && StringUtils.isNotBlank(cmd.getTargetUserKey())) {
            result.addError("目标用户存在于redis中的键（即targetUserKey属性）与users不能同时使用");
        }
        if (cmd.getTags() != null && cmd.getTags().size() > 20) {
            result.addError("tags元素不能超过20个");
        }
        if (cmd.getTagAndList() != null && cmd.getTagAndList().size() > 20) {
            result.addError("tagAndList元素不能超过20个");
        }
        if (cmd.getTagNotList() != null && cmd.getTagNotList().size() > 20) {
            result.addError("tagNotList元素不能超过20个");
        }
        return result.isEmpty();
    }

}
